import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NoteSystem extends JFrame implements ActionListener{
    JTextField textField;
    JMenuBar mb=new JMenuBar();            //˵
    //˵
    JMenu m1=new JMenu("ļ");             //˵
    JMenu m2=new JMenu("༭");
    JMenu m3=new JMenu("");
    JMenuItem mi1=new JMenuItem("");//˵
    JMenuItem mi2=new JMenuItem("");
    JMenuItem mi3=new JMenuItem("˳");
    //ʽ˵
    JPopupMenu popup=new JPopupMenu();
    JMenuItem pmi1=new JMenuItem("");
    JMenuItem pmi2=new JMenuItem("");
    JMenuItem pmi3=new JMenuItem("ճ");
    public NoteSystem(){
        super("±");
        setJMenuBar(mb);
        mb.add(m1);
        mb.add(m2);
        mb.add(m3); 
        mi1.addActionListener(this);//Բ˵ע
        mi2.addActionListener(this);
        mi3.addActionListener(this);
        m1.add(mi1);
        m1.add(mi2);
        m1.addSeparator();                                                //ӷָ
        m1.add(mi3);
        m2.add(new JCheckBoxMenuItem(""));      //ѡ˵
        m3.add("");
        m3.add("");
        m3.addSeparator();
        m3.add("...");
        popup.add(pmi1);
        popup.add(pmi2);
        popup.add(pmi3);
        //ʵֵʽ˵
        getContentPane().addMouseListener(new MouseAdapter(){   //Ƕʽʵ¼
            public void mouseReleased(MouseEvent e){
            	  if(e.isPopupTrigger()){
            		    popup.show(e.getComponent(),e.getX(),e.getY());    //ʾʽ˵}
            }
        });
         textField=new JTextField();//ı
         getContentPane().add(textField,BorderLayout.SOUTH);
    }
    public void actionPerformed(ActionEvent e){
         JMenuItem select=(JMenuItem)e.getSource();
         textField.setText("ѡǣ"+select.getText()); //õ˵ϵıʾ
         JFileChooser fileChooser=new JFileChooser();    //ļԻ
         if(select.equals(mi1)){ //ʾļ򿪶Ի
             if(fileChooser.showOpenDialog(this)==JFileChooser.APPROVE_OPTION) {
            	 JOptionPane.showConfirmDialog(this,"Ҫ"+fileChooser.getSelectedFile()+
"ļ","ļϢ",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);
	}
         }
         if(select.equals(mi2)){ //ʾļԻ
             if(fileChooser.showSaveDialog(this)==JFileChooser.APPROVE_OPTION) {
            	   JOptionPane.showConfirmDialog(this,"Ҫ"+fileChooser.getSelectedFile()+"ļ","ļϢ",JOptionPane.YES_NO_OPTION,JOptionPane.INFORMATION_MESSAGE);}
          }
          if(select.equals(mi3)){
            	  JOptionPane.showConfirmDialog(this,"˳","ȷʾ",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);}
    }
    public static void main(String args[]){
        JFrame frame=new NoteSystem();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600,500);
        frame.setVisible(true);
    }
}
